package ms.unicorn.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.resource.ResourceItemProvider;
import org.eclipse.emf.edit.provider.resource.ResourceSetItemProvider;

public class UnicornResourceItemProvider extends ResourceItemProvider {

	public UnicornResourceItemProvider(AdapterFactory adapterFactory) {
		super(adapterFactory);
	}

	@Override
	public Collection<?> getChildren(Object object) {
		// Don't include controlled children here, they'll show up under their container.
	    //
	    List<EObject> contents = ((Resource)object).getContents();
	    Collection<Object> result = new ArrayList<Object>(contents.size());
	    for (Object o : contents)
	    {
	      if (!AdapterFactoryEditingDomain.isControlled(o) && o instanceof ms.unicorn.Diagram)
	      {
	        result.add(o);
	      }
	    }
	    return result;
	}

}
